//
//  FirstViewController.m
//  ThemeManager
//
//  Created by weiguang on 2017/1/13.
//  Copyright © 2017年 weiguang. All rights reserved.
//

#import "FirstViewController.h"


@interface FirstViewController ()
@property(nonatomic,copy)NSArray *data;

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGBA(239, 239, 239, 1.0);
    self.data = @[@"红",@"黄",@"蓝",@"默认"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _data.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"First" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"First"];
    }
    
    cell.textLabel.text = self.data[indexPath.row];
    cell.textLabel.textColor = [[ThemeManger shareInstance] getThemeColor];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
            //红
            [[ThemeManger shareInstance] setThemeColor:RGBA(227, 53, 94, 1.0)];
            // 发送一个kThemeDidChangeNotification的通知，切换主题
            break;
        case 1:
            //黄
            [[ThemeManger shareInstance] setThemeColor:RGBA(227, 198, 94, 1.0)];
            break;
        case 2:
            //蓝
            [[ThemeManger shareInstance] setThemeColor:RGBA(58, 147, 195, 1.0)];
            break;
        case 3:
            //默认
            [[ThemeManger shareInstance] setThemeColor:RGBA(74, 125, 112, 1.0)];
            break;
            
        default:
            break;
    }
    
    [[NSNotificationCenter defaultCenter] postNotificationName:kThemeColorChangeNotification object:nil];
    
    [self.tableView reloadData];

}



@end
